package com.jf3q.front.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jf3q.common.domain.EduCourse;
import com.jf3q.common.mapper.EduCourseMapper;
import com.jf3q.common.vo.CourseWebVo;
import com.jf3q.front.service.EduCourseWebService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
@CacheConfig(cacheNames = "course")
public class EduCourseWebServiceImpl extends ServiceImpl<EduCourseMapper, EduCourse>
        implements EduCourseWebService {

    //根据课程id查询课程基本信息
    @Override
    @Cacheable(key="#id")
    public CourseWebVo selectInfoWebById(String id) {
        this.updatePageViewCount(id);
        return baseMapper.selectInfoWebById(id);
    }

    //更新课程浏览数量
    @Override
    public void updatePageViewCount(String id) {
        EduCourse course = baseMapper.selectById(id);
        course.setViewCount(course.getViewCount()+1);
        baseMapper.updateById(course);
    }
}
